package com.bzxgc.sgwer.config;

import com.bzxgc.sgwer.common.Interceptor.GlobalInterceptor;
import com.bzxgc.sgwer.common.Interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/login").setViewName("login");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 拦截器按照顺序执行
         */
//        registry.addInterceptor(new TwoInterceptor()).addPathPatterns("/two/**").addPathPatterns("/one/**");
//        registry.addInterceptor(new OneInterceptor()).addPathPatterns("/one/**");
        List<String> excludePathPatterns = new ArrayList<>();
        excludePathPatterns.add("/login");
        excludePathPatterns.add("/*/ajax/**");
        excludePathPatterns.add("/css/**");
        excludePathPatterns.add("/custom/**");
        excludePathPatterns.add("/font-awesome/**");
        excludePathPatterns.add("/fonts/**");
        excludePathPatterns.add("/img/**");
        excludePathPatterns.add("/js/**");
        excludePathPatterns.add("/component/**");
        registry.addInterceptor(new GlobalInterceptor()).addPathPatterns("/**").excludePathPatterns(excludePathPatterns);
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns(excludePathPatterns);
    }
}
